#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QKeyEvent>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{

    int x=ui->pushButton->geometry().x();
    int y=ui->pushButton->geometry().y();
    int w=ui->pushButton->geometry().width();
    int h=ui->pushButton->geometry().height();


    if(event->key()==Qt::Key_W){
        ui->pushButton->setGeometry(x,y-5,w,h);
    }
    if(event->key()==Qt::Key_S){
        ui->pushButton->setGeometry(x,y+5,w,h);

    }if(event->key()==Qt::Key_A){
        ui->pushButton->setGeometry(x-5,y,w,h);

    }if(event->key()==Qt::Key_D){
        ui->pushButton->setGeometry(x+5,y,w,h);

    }
}

